/*
 * maz_app_idle.c
 *
 *  Created on: 2020年6月14日
 *      Author: Paul
 */

#include "maz_app.h"
#include "maz_com.h"
#include "maz_drv.h"
#include "maz_mod.h"

/**
 * "dlvl" variables must be defined if debug message is to be printed through the dlog/dmsg, and "dlvl" must be declared static
 */
static int dlvl = DINF;

osThreadId_t idle_taskHandle;
const osThreadAttr_t idle_task_attributes =
{
    .name = "idle_task",
    .priority = (osPriority_t) osPriorityNormal,
    .stack_size = 128 * 4
};

static MAZMOD_LED_CTRL ip5306 =
{
    .cfg.gpio.cfg.port  = GPIOC,
    .cfg.gpio.cfg.pin   = GPIO_PIN_13,
    .cfg.polar          = MAZMOD_E_LED_POLAR_LOW,
    .cfg.status         = MAZMOD_E_LED_STATUS_OFF,
};

int MAZ_App_idle_preinit(void)
{
    return MAZRET_OK;
}

int MAZ_App_idle_init(void)
{
    idle_taskHandle = osThreadNew(MAZ_App_idle_task, NULL, &idle_task_attributes);
    MAZASSERT_RETVAL(NULL == idle_taskHandle, MAZRET_ENULLP, "err: osThreadNew MAZ_App_idle_task");

    return MAZRET_OK;
}

void MAZ_App_idle_task(void *argument)
{
    MAZ_Mod_led_init(&ip5306);

    while(1)
    {
        osDelay(500);
        MAZ_Mod_led_status_set(&ip5306, MAZMOD_E_LED_STATUS_ON);
        osDelay(500);
        MAZ_Mod_led_status_set(&ip5306, MAZMOD_E_LED_STATUS_OFF);
    }
}
